#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int is_use[1005] = {0};
int num_arr[11] = {0};
int ret = 0x3f3f3f3f;
int n = 0;

bool IsPrimeNumber(int num)
{
    for(int i = 2; i <= std::sqrt(num); i++)
    {
        if(num % i == 0) return false;
    }
    return true;
}

void dfs(int level, int total)
{
    //终止条件
    if(level == n)
    {
        ret = min(total, ret);
        return;
    }
    for(int i = 2; i <= num_arr[level]; i++)
    {
        if(num_arr[level] % i != 0 || (!IsPrimeNumber(i))) continue;
        if(is_use[i] == 1) continue;
        is_use[i] = 1;
        dfs(level + 1, total + i);
        is_use[i] = 0;
    }
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> num_arr[i];
    dfs(0, 0);
    if(ret == 0x3f3f3f3f) std::cout << -1;
    else std::cout << ret;
    return 0;
}